#ifndef CDataConnection_H_
#define CDataConnection_H_

#include <es_sock.h>
#include <in_sock.h>

#include "CDataCellId.h"
#include "DataStruct.h"
#include "Common.h"
#include "MGpsObserver.h"


#ifdef __LOGGER
	#include <flogger.h>
#endif

enum TCDataConnectionProgress 
{
	EDataIdle,
	EDataResolving,
	EDataSending,
	EDataWaiting,
};

class CDataConnection: public CActive
{

public:
	static CDataConnection* NewL(RSocketServ& aSocketServ,TDesC& aServerName, TUint aNodeid, TUint aPort, TUint aInterval,MDisplayObserver& aDisplay, MGpsObserver& aGpsObserver);
	CDataConnection(RSocketServ& aSocketServ, TDesC& aServerName, TUint aNodeid, TUint aPort, TUint aInterval, MDisplayObserver& aDisplay, MGpsObserver& aGpsObserver);
	virtual ~CDataConnection();
	
	TInt Start();
	void Stop();
	void setNodeid(TUint aNodeid);
	void setInterval(TUint aInterval);
	void setServer(const TDesC& aServerName);
	void setPort(TUint aPort);
	TBool IsRunning();

private:
	void ConstructL();
	
	//CActive methods
	void DoCancel(); 
    void RunL();
    
    void SendData();
    void CloseConnection();	
    
    void updateScreen();
	
	
//Private attributes
private:
	//Constructor argument	
	RSocketServ& iSocketServ;
	TBuf<SERVERNAMELENGTH> iServerName;
	TUint iNodeid;
	struct _device iNode;
	TUint iPort;
	TUint iInterval;
	MDisplayObserver& iDisplay;
	MGpsObserver& iGpsObserver;
	
	RSocket iSocket;
	RHostResolver iResolver ;
	TNameEntry iHostAddress ;
	TCDataConnectionProgress iState;
	TInetAddr iInetAddress;
	RTimer iTimmer;
	
	TUint iGpsFix;
	
	//CDataCellId* iDataCellId;
	TBool iChangingInterval; /* true when we are in the middle of this operation, otherwise false */
	
	#ifdef __LOGGER
		RFileLogger iLog;
	#endif
	
};

#endif /*CDataConnection_H_*/
